package com.em.tuppence.backend.infinispan;

import java.io.IOException;

import org.infinispan.Cache;
import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager;

public enum InfinispanManager {
	
	INSTANCE;
	
	private EmbeddedCacheManager manager = null;
	
	private InfinispanManager() {
		this.initialize();
	}
	
	private void initialize() {
		//create a cache manager with the configuration we created
		try {
			this.manager = new DefaultCacheManager("infinispan.xml");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public <K,V> Cache<K,V> getCache(String cacheName, Class<K> k, Class<V> v) {
		Cache<K, V> cache = this.manager.getCache(cacheName, true);
		return cache;
	}
	
}
